package com.example.taximeter.service.impl;


import com.example.taximeter.bean.Privilege;
import com.example.taximeter.bean.RolePrivilege;
import com.example.taximeter.mapper.PrivilegeMapper;
import com.example.taximeter.mapper.RoleMapper;
import com.example.taximeter.service.PrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 权限
 */
@Service
public class PrivilegeServiceImpl implements PrivilegeService {

    private PrivilegeMapper privilegeMapper;
    private RoleMapper roleMapper;

    @Autowired
    public PrivilegeServiceImpl(PrivilegeMapper privilegeMapper,RoleMapper roleMapper){
        this.privilegeMapper = privilegeMapper;
        this.roleMapper = roleMapper;
    }


    @Override
    public List<RolePrivilege> findPriviegeByRole(Integer roleid) {
        return privilegeMapper.findRolePrivilegeByRoleid(roleid);
    }

    @Override
    public List<RolePrivilege> findPriviegeAllByRole(Integer roleid) {
        return privilegeMapper.findRolePrivilegeAllByRoleid(roleid);
    }

    @Override
    public List<Privilege> findPrivinfoByRole(Integer roleid) {

        ArrayList<Privilege> privileges = new ArrayList<>();
        List<RolePrivilege> rolePrivileges =  privilegeMapper.findRolePrivilegeByRoleid(roleid);
        for(RolePrivilege rolePrivilege:rolePrivileges){
            privileges.add(privilegeMapper.findPrivilegeByRoleid(rolePrivilege.getPrivilegeid()));
        }


        return privileges;
    }

    @Override
    public List<Privilege> findPrivilegelist() {
        return privilegeMapper.findPrivilegelist();
    }
}
